package commande.os.windows;

import java.io.File;
import java.util.Properties;

import librairies.liste.interfaces.IListeE;
import librairies.liste.list.ListeDCE;
import IO.properties.PropertiesLoader;

import commande.interfaces.ILien;

/**
 * Gestion des liens sous windows. 
 * 
 * @author mlozach
 */
public class LienWindows implements ILien
{
	private String lienProperties;
	private String lienXml;
	private String lienDico;
	private String slash;
	private String racine;
	
	private Properties prop;
	
	public LienWindows() 
	{
		this.lienProperties = new String("configuration\\config\\properties\\");
		this.lienXml = new String("configuration\\config\\xml\\");
		this.lienDico = new String("configuration\\config\\xml\\dico\\");
		this.slash = new String("\\");
		this.racine = new String("c:\\");
		
		this.prop = PropertiesLoader.load(lienProperties + "windows.properties");
	}
	
	@Override
	public IListeE<String> getRacinePotentielle()
	{
		IListeE<String> chemainPotentielle = new ListeDCE<String>();
		
		String potentielle = this.prop.getProperty("lien.racinePotentielle");
		
		String[] tab = potentielle.split(" ");
		
		for(int i = 0; i < tab.length; ++i)
		{
			if(isLien(tab[i]))
			{
				chemainPotentielle.add(tab[i]);
			}
		}
		
		return chemainPotentielle;
	}

	@Override
	public boolean isLien(String lien)
	{
		if(lien == null)
		{
			return false;
		}
		
		File file = new File(lien);
		
		if(file.exists())
		{
			return true;
		}
		
		return false;
	}
	
	@Override
	public String getValeurOs(String key) 
	{
		if(this.prop == null) return null;
		return this.prop.getProperty(key);
	}
	
	@Override
	public String getLienProperties() {return lienProperties;}
	@Override
	public String getLienXml() {return lienXml;}
	@Override
	public String getLienDico() {return lienDico;}
	@Override
	public String getSlash() {return slash;}
	@Override
	public String getRacine() {return racine;}
}